package com.qingxin.sys.entity;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.format.annotation.DateTimeFormat;

/**
 * 用户表
 * @author Administrator
 *
 */
@Entity
@Table(name = "sys_user")
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
public class SysUser extends BaseEntity implements java.io.Serializable {
	private static final long serialVersionUID = -2445176313055811827L;

	private String userid;
	private String login_name;
	private String username;
	private String password;//password=md5(orgPwd+salt)
	private String salt;//10为随机串
	private String phone;
	private String email;
	private String wx_openid;
	private String user_type;//用户类型：0超级管理员、1公司管理员、2普通用户
	private String user_status;//用户状态1:正常2:已停用
	private Integer ishide;
	private String regionid;
	private String photo;
	private String remark;
	private String companyid;
	private String create_by;
	private Date create_time;
	private String update_by;
	private Date update_time;
	
	
	private String address;//地址
	private String job;//职业
	private String sex;//性别：男/女
	@DateTimeFormat(pattern="yyyy-MM-dd")
	private Date birthday;//出生日期
	private String tokenid;
	
	private Set<SysUserRights> sysUserRights = new HashSet<>(0);
	
	private String companyName;
	
	public SysUser() {
	}
	
	public SysUser(String userid) {
		this.userid = userid;
	}

	
	public SysUser(String userid, String login_name, String username) {
		this.userid = userid;
		this.login_name = login_name;
		this.username = username;
	}

	
	public SysUser(String userid, String login_name, String username,
			String phone, String email, String job, String sex, String user_type, String companyName) {
		this.userid = userid;
		this.login_name = login_name;
		this.username = username;
		this.phone = phone;
		this.email = email;
		this.job = job;
		this.sex = sex;
		this.user_type = user_type;
		this.companyName = companyName;
	}

	
	@GenericGenerator(name = "generator", strategy = "uuid.hex")
	@Id
	@GeneratedValue(generator = "generator")
	@Column(name = "userid", unique = true, nullable = false, length = 32)
	public String getUserid() {
		return userid;
	}
	public void setUserid(String userid) {
		this.userid = userid;
	}

	@Column(name = "login_name", length = 20)
	public String getLogin_name() {
		return login_name;
	}
	public void setLogin_name(String login_name) {
		this.login_name = login_name;
	}

	@Column(name = "username", length = 20)
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}

	@Column(name = "password", length = 32)
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}

	@Column(name = "salt", length = 10)
	public String getSalt() {
		return salt;
	}
	public void setSalt(String salt) {
		this.salt = salt;
	}

	@Column(name = "phone", length = 20)
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}

	@Column(name = "email", length = 50)
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}

	@Column(name = "wx_openid", length = 50)
	public String getWx_openid() {
		return wx_openid;
	}
	public void setWx_openid(String wx_openid) {
		this.wx_openid = wx_openid;
	}

	@Column(name = "user_type", length = 1)
	public String getUser_type() {
		return user_type;
	}
	public void setUser_type(String user_type) {
		this.user_type = user_type;
	}

	@Column(name = "user_status", length = 1)
	public String getUser_status() {
		return user_status;
	}
	public void setUser_status(String user_status) {
		this.user_status = user_status;
	}

	@Column(name = "ishide")
	public Integer getIshide() {
		return ishide;
	}
	public void setIshide(Integer ishide) {
		this.ishide = ishide;
	}

	@Column(name = "regionid", length = 50)
	public String getRegionid() {
		return regionid;
	}
	public void setRegionid(String regionid) {
		this.regionid = regionid;
	}

	@Column(name = "photo", length = 100)
	public String getPhoto() {
		return photo;
	}
	public void setPhoto(String photo) {
		this.photo = photo;
	}

	@Column(name = "remark", length = 2000)
	public String getRemark() {
		return remark;
	}
	public void setRemark(String remark) {
		this.remark = remark;
	}

	@Column(name = "companyid", length = 32)
	public String getCompanyid() {
		return companyid;
	}
	public void setCompanyid(String companyid) {
		this.companyid = companyid;
	}

	@Column(name = "create_by", length = 50)
	public String getCreate_by() {
		return create_by;
	}
	public void setCreate_by(String create_by) {
		this.create_by = create_by;
	}

	@Column(name = "create_time", length = 23)
	public Date getCreate_time() {
		return create_time;
	}
	public void setCreate_time(Date create_time) {
		this.create_time = create_time;
	}

	@Column(name = "update_by", length = 50)
	public String getUpdate_by() {
		return update_by;
	}
	public void setUpdate_by(String update_by) {
		this.update_by = update_by;
	}

	@Column(name = "update_time", length = 23)
	public Date getUpdate_time() {
		return update_time;
	}
	public void setUpdate_time(Date update_time) {
		this.update_time = update_time;
	}
	
	
	@Column(name = "address", length = 500)
	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}
	
	@Column(name = "job", length = 50)
	public String getJob() {
		return job;
	}

	public void setJob(String job) {
		this.job = job;
	}
	
	@Column(name = "sex", length = 10)
	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	@Column(name = "birthday", length = 23)
	public Date getBirthday() {
		return birthday;
	}

	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}
	
	@Column(name = "tokenid", length = 16)
	public String getTokenid() {
		return tokenid;
	}
	public void setTokenid(String tokenid) {
		this.tokenid = tokenid;
	}
	
	
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "sysUser")
	@JsonIgnore
	public Set<SysUserRights> getSysUserRights() {
		return sysUserRights;
	}

	public void setSysUserRights(Set<SysUserRights> sysUserRights) {
		this.sysUserRights = sysUserRights;
	}
	
	
	@Transient
	public String getCompanyName() {
		return companyName;
	}
	public void setCompanyName(String companyName) {
		this.companyName = companyName;
	}
	
}
